define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function() {
		this.callParent();
	};

	Model.prototype.cartShopDataCustomRefresh = function(event) {
		var url = require.toUrl("./json/cartShopData.json");
		$.ajaxSettings.async = false;
		$.getJSON(url, function(data) {
			event.source.loadData(data);
		});

	};

	Model.prototype.cartGoodsDataCustomRefresh = function(event) {
		var url = require.toUrl("./json/cartGoodsData.json");
		$.ajaxSettings.async = false;
		$.getJSON(url, function(data) {
			event.source.loadData(data);
		});
	};

	Model.prototype.checkbox1Change = function(event) {
		var row = event.bindingContext.$object;
		var shopID = row.val("id");
		var rows = this.comp("cartGoodsData").find([ "fShopID" ], [ shopID ]);
		for (var i = 0; i < rows.length; i++) {
			rows[i].val('fCheck', event.value);
		}
	};

	Model.prototype.checkbox2Change = function(event) {
		var row = event.bindingContext.$object;
		var shopID = row.val("fShopID");
		var rows = this.comp("cartGoodsData").find([ "fShopID", "fCheck" ], [ shopID, 1 ]);
		var rowsNum = rows.length;
		if (event.checked) {
			rowsNum++;
		} else {
			rowsNum--;
		}
		if (rowsNum > 0) {
			this.comp("cartShopData").setValueByID("fCheck", 1, shopID);
		} else {
			this.comp("cartShopData").setValueByID("fCheck", "", shopID);
		}

	};

	Model.prototype.button1Click = function(event) {
		var row = event.bindingContext.$object;
		row.val("fNumber", row.val("fNumber") > 1 ? row.val("fNumber") - 1 : 1);
	};

	Model.prototype.button2Click = function(event) {
		var row = event.bindingContext.$object;
		row.val("fNumber", row.val("fNumber") + 1);
	};

	return Model;
});